<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class UserAddrRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => 'required',
            'phone' => ['required','regex:/^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147)|(145))\\d{8}$/'],
            'province' => 'required',
            'city' => 'required',
            'street' => 'required',
            'detail' => 'required',
            'is_default' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'username.required' => '请输入收件人', 
            'phone.required' => '请输入收件人手机号', 
            'phone.regex' => '手机号格式错误', 
            'province.required' => '请输入省份', 
            'city.required' => '请输入城市', 
            'street.required' => '请输入县/区', 
            'detail.required' => '请输入详细地址', 
            'is_default.required' => '请选择是否默认',
        ];
    }
}
